﻿// ______________________________________________________________
//
// Liam O'Donnell
// Graphics tools
// ______________________________________________________________
//

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.Point;

class com.spikything.gfx.GfxTools {

	function GfxTools () {};

	public static function createSnapshot (base:MovieClip, mc:MovieClip):MovieClip {
		var bounds = mc.getBounds(base);
		var bmpWidth = bounds.xMax-bounds.xMin;
		var bmpHeight = bounds.yMax-bounds.yMin;
		var bmp1 = new BitmapData(bmpWidth, bmpHeight, true, 0x00000000);
		var snapshot = base.createEmptyMovieClip("snapshot", base.getNextHighestDepth());
		snapshot._x = mc._x;
		snapshot._y = mc._y;
		var rect = new Rectangle(0,0,bmpWidth, bmpHeight);
		var pos = new Point(0,0);
		bmp1.draw(mc, new Matrix(mc._xscale/100, 0, 0, mc._yscale/100, mc._x-bounds.xMin, mc._y-bounds.yMin));
		snapshot.attachBitmap(bmp1, 1, "auto", true);
		snapshot._x = bounds.xMin;
		snapshot._y = bounds.yMin;
		mc.unloadMovie();
		return snapshot;
	}

}